<template>
  <div class="repairRecord">
    <div class="searchDiv">
      <Form :model="searchItem" :label-width="90">
        <Row :gutter="10">
          <Col span="6">
            <FormItem label="电站">
              <Select v-model="searchItem.powerStation" clearable filterable @on-change="getHd">
                <Option
                  v-for="(item, index) in powerStationList"
                  :value="item"
                  :key="index"
                >{{ item }}</Option>
              </Select>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="HD编号">
              <Select
                v-model="searchItem.hdNumber"
                clearable
                filterable
                :disabled="HBnumberList.length == 0"
                @on-change="getJz"
              >
                <Option v-for="(item, index) in HBnumberList" :value="item" :key="index">{{ item }}</Option>
              </Select>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="机组编号">
              <Select
                v-model="searchItem.aircrewNumber"
                clearable
                filterable
                :disabled="JZnumberList.length == 0"
              >
                <Option v-for="(item, index) in JZnumberList" :value="item" :key="index">{{ item }}</Option>
              </Select>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="维修编号">
              <Input v-model="searchItem.maintainCode" placeholder="请输入"></Input>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="计划开始时间">
              <DatePicker
                type="date"
                placeholder="选择日期"
                @on-change="time1"
                 format="yyyy-MM-dd HH:mm:ss"
                style="width: 100%"
              ></DatePicker>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="计划完成时间">
              <DatePicker
                type="date"
                placeholder="选择日期"
                @on-change="time2"
                 format="yyyy-MM-dd HH:mm:ss"
                style="width: 100%"
              ></DatePicker>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="记录人">
              <Select v-model="searchItem.recordName" clearable filterable>
                          <Option v-for="(item, index) in peopleList" :value="item.trueName" :key="index">{{item.trueName}}</Option>
                      </Select>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="记录时间">
              <DatePicker
                type="datetimerange"
                 @on-change="time3"
                placeholder="记录时间"
                style="width: 100%"
              ></DatePicker>
            </FormItem>
          </Col>
          <Col span="12">
            <Button type="primary" class="marRight" @click="pageNo=1;getDataList()">查询</Button>
            <Button type="success" class="marRight" @click="formItem={};tableData2=[];tableData3=[];add()">新增记录</Button>
            <Button type="primary" @click="downBtn">导出Excel</Button>
          </Col>
        </Row>
      </Form>
    </div>
    <Table style="margin-top:10px;" border :columns="columns" :loading="loading" :data="tableData"></Table>
    <Page show-total :total="total" :page-size="pageSize" @on-change="changePage" :current="pageNo"  style="margin:20px auto;text-align:center"/>
    <!-- 新增弹窗开始 -->
    <Modal :mask-closable="false" v-model="modal1" :title="title1" width="1000" >
      <div class="baseTitle">基本信息</div>
           <Form :label-width="100">
             <Row :gutter="10" class="xzjz">
                 <Col span="8">
                    <FormItem :model="formItem" label="电站：">
                      <Input v-model="formItem.powerStation" disabled ></Input>
                     <!-- <Select v-model="formItem.powerStation" clearable filterable @on-change="getHd">
                        <Option v-for="(item, index) in powerStationList" :value="item" :key="index">{{item}}</Option>
                    </Select> -->

                    </FormItem>
                  </Col>
                  <Col span="8">
                    <FormItem label="HD编号：">
                      <Input v-model="formItem.hdNumber" disabled ></Input>
                      <!-- <Select v-model="formItem.hdNumber" clearable filterable :disabled="HBnumberList.length==0" @on-change="getJz">
                        <Option v-for="(item, index) in HBnumberList" :value="item" :key="index">{{item}}</Option>
                    </Select> -->
                    </FormItem>
                  </Col>
                  <Col span="8">
                    <FormItem label="机组编号：">
                      <Input v-model="formItem.aircrewNumber" disabled ></Input>
                        <!-- <Select v-model="formItem.aircrewNumber" clearable filterable :disabled="JZnumberList.length==0" @on-change="getMode">
                          <Option v-for="(item, index) in JZnumberList" :value="item" :key="index">{{item}}</Option>
                      </Select> -->
                    </FormItem>
                  </Col>
                  <Col span="8">
                    <FormItem label="型号：">
                      <Input v-model="formItem.model" disabled ></Input>
                    </FormItem>
                  </Col>
             </Row>
           </Form>
           <div class="baseTitle">维修信息</div>
           <Form :label-width="100">
             <Row :gutter="10" class="xzjz">
                 <Col span="8">
                    <FormItem label="维修编号：">
                      <Input v-model="formItem.maintainCode" disabled></Input>
                    </FormItem>
                  </Col>
                  <Col span="8">
                    <FormItem label="维修类别：">
                    <Select v-model="formItem.maintainTypeDictId" clearable filterable @on-change="getSelect1">
                          <Option v-for="(item, index) in maintainCategoryList" :value="item.id" :key="index">{{item.displayName}}</Option>
                      </Select>
                    </FormItem>
                  </Col>
                  <Col span="8">
                    <FormItem label="计划开始时间：">
                      <Input v-model="formItem.planStartTime" disabled></Input>
                      <!-- <DatePicker
                      disabled
                        type="datetime"
                        v-model="formItem.planStartTime"
                         @on-change="time4"
                         format="yyyy-MM-dd HH:mm:ss"
                        placeholder="选择日期"
                        style="width: 100%"
                      ></DatePicker> -->
                    </FormItem>
                  </Col>
                   <Col span="8">
                    <FormItem label="计划结束时间：">
                       <Input v-model="formItem.planEndTime" disabled></Input>
                     <!-- <DatePicker
                     disabled
                        type="datetime"
                        v-model="formItem.planEndTime"
                         @on-change="time5"
                         format="yyyy-MM-dd HH:mm:ss"
                        placeholder="选择日期"
                        style="width: 100%"
                      ></DatePicker> -->
                    </FormItem>
                  </Col>
                  <Col span="8">
                    <FormItem label="维修工期(天)：">
                      <Input v-model="formItem.maintainDays" disabled placeholder="请输入"></Input>
                    </FormItem>
                  </Col>
                  <Col span="8">
                    <FormItem label="维修状态：">
                       <Select v-model="formItem.maintainStatusDictId" clearable filterable @on-change="getSelect2">
                          <Option v-for="(item, index) in maintainStatusList" :value="item.id" :key="index">{{item.displayName}}</Option>
                      </Select>
                    </FormItem>
                  </Col>
                  <Col span="8">
                    <FormItem label="维修经理：">
                     <Input v-model="formItem.maintainManager" disabled placeholder="请输入"></Input>
                    </FormItem>
                  </Col>
                  <Col span="8">
                    <FormItem label="维修单号：">
                      <Input v-model="formItem.maintainNumber" placeholder="请输入"></Input>
                    </FormItem>
                  </Col>
             </Row>
           </Form>
           <div class="baseTitle">维修内容</div>
           <Form :label-width="80">
             <Row :gutter="10" class="xzjz">
                  <Col span="24">
                     <Input type="textarea" style="margin-bottom:15px;" :maxlength="200" :rows="4" v-model="formItem.maintainContent" placeholder="请输入"></Input>
                  </Col>
                  <div class="baseTitle">异常记录</div>
                  <Col span="6">
                    <FormItem label="功能位置：">
                      <Input v-model="yichangForm.location" :maxlength="20" placeholder="请输入"></Input>
                    </FormItem>
                  </Col>
                  <Col span="6">
                    <FormItem label="异常描述：">
                      <Input v-model="yichangForm.description" :maxlength="50" placeholder="请输入"></Input>
                    </FormItem>
                  </Col>
                  <Col span="6">
                    <FormItem label="处理结果：">
                      <Input v-model="yichangForm.result" :maxlength="50" placeholder="请输入"></Input>
                    </FormItem>
                  </Col>
                  <Col span="6">
                    <Upload
                      style="float:left;margin-right:10px;"
                          :headers='fileheader'
                          :on-success='fileSuccess'
                          :show-upload-list='false'
                          :action="apihost+'/admin-api/admins/upload/uploadFile'">
                          <Button icon="ios-cloud-upload-outline">选择图片</Button>
                      </Upload>
                    <Button type="default" @click="addYc"> 添加</Button>
                  </Col>
                  <Col span="24" style="overflow:hidden;text-align:right;margin-bottom:10px;" v-if="yichangForm.picUrl!=''" >
                      <span style="">{{yichangForm.picUrl.substring(yichangForm.picUrl.lastIndexOf('/')+1)}}</span>
                      <Button size="small" style="margin-left:30px;margin-right:10px;"  @click="xiazai(yichangForm.picUrl)" type="primary">下载文件</Button>
                      <Button size="small"  @click="yichangForm.picUrl=''" type="error">删除</Button>
                  </Col>
                  <Col span="24" style="margin-bottom:10px;">
                    <Table border :columns="columns2" :data="tableData2"></Table>
                  </Col>
                  <div class="baseTitle">上传附件</div>
                  <Col span="12">
                    <FormItem label="附件标题">
                      <Input v-model="fujianForm.title" :maxlength="20" placeholder="请输入"></Input>
                    </FormItem>
                  </Col>
                  <Col span="12">
                     <Upload
                      style="float:left;margin-right:10px;"
                          :headers='fileheader'
                          :on-success='fileSuccess2'
                          :show-upload-list='false'
                          :action="apihost+'/admin-api/admins/upload/uploadFile'">
                          <Button icon="ios-cloud-upload-outline">选择附件</Button>
                      </Upload>
                    <Button type="default" @click="addFj"> 添加</Button>
                  </Col>
                  <Col span="24" style="overflow:hidden;text-align:right;margin-bottom:10px;" v-if="fujianForm.url!=''" >
                      <span style="">{{fujianForm.url.substring(fujianForm.url.lastIndexOf('/')+1)}}</span>
                      <Button size="small" style="margin-left:30px;margin-right:10px;"  @click="xiazai(fujianForm.url)" type="primary">下载文件</Button>
                      <Button size="small"  @click="fujianForm.url=''" type="error">删除</Button>
                  </Col>
                   <Col span="24" style="margin-bottom:10px;">
                    <Table border :columns="columns3" :data="tableData3"></Table>
                  </Col>
                  <div class="baseTitle">填报信息</div>
                  <Col span="8">
                    <FormItem label="记录人：">
                       <Input v-model="recordName" disabled placeholder="请输入"></Input>
                    </FormItem>
                  </Col>
                  <Col span="8">
                    <FormItem label="记录时间：">
                     <Input v-model="recordTime" disabled placeholder="请输入"></Input>
                    </FormItem>
                  </Col>
             </Row>
           </Form>
           <div slot="footer">
               <Button @click="modal1=false">取消</Button>
              <Button type="primary" :loading="btnClick" @click="ok">确定</Button>
          </div>
    </Modal>
    <!-- 新增弹窗结束 -->
    <Modal :mask-closable="false" v-model="modal2" width="360" class-name="vertical-center-modal" @on-ok="remove(delIndex)">
        <p slot="header" style="color:#f60;text-align:center">
            <Icon type="ios-information-circle"></Icon>
            <span>确认删除</span>
        </p>
        <div style="text-align:center">
            <p>确认删除此数据么？</p>
        </div>
    </Modal>

    <!-- 维修计划列表 -->
    <Modal :mask-closable="false" v-model="modal0" width="1000" :footer-hide="true" class-name="vertical-center-modal">
           <div class="searchDiv">
      <Form :model="searchItem2" :label-width="90">
        <Row :gutter="10">
          <Col span="6">
            <FormItem label="电站">
              <Select v-model="searchItem2.powerStation" clearable filterable @on-change="getHd2">
                <Option
                  v-for="(item, index) in powerStationList"
                  :value="item"
                  :key="index"
                >{{ item }}</Option>
              </Select>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="HD编号">
              <Select
                v-model="searchItem2.hdNumber"
                clearable
                filterable
                :disabled="HBnumberList.length == 0"
                @on-change="getJz2"
              >
                <Option v-for="(item, index) in HBnumberList" :value="item" :key="index">{{ item }}</Option>
              </Select>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="机组编号">
              <Select
                v-model="searchItem2.aircrewNumber"
                clearable
                filterable
                :disabled="JZnumberList.length == 0"
              >
                <Option v-for="(item, index) in JZnumberList" :value="item" :key="index">{{ item }}</Option>
              </Select>
            </FormItem>
          </Col>
          <!-- <Col span="6">
            <FormItem label="维修编号">
              <Input v-model="searchItem2.repairCode" placeholder="请输入"></Input>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="计划开始时间">
              <DatePicker
                type="date"
                v-model="searchItem2.startTime"
                 @on-change="time1a"
                 format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择日期"
                style="width: 100%"
              ></DatePicker>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="计划完成时间">
              <DatePicker
                type="date"
                v-model="searchItem2.endTime"
                 @on-change="time2a"
                 format="yyyy-MM-dd HH:mm:ss"
                placeholder="选择日期"
                style="width: 100%"
              ></DatePicker>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="记录人">
              <Select v-model="searchItem2.recordName" clearable filterable>
                          <Option v-for="(item, index) in peopleList" :value="item.trueName" :key="index">{{item.trueName}}</Option>
                      </Select>
            </FormItem>
          </Col>
          <Col span="6">
            <FormItem label="记录时间">
              <DatePicker
                type="datetime"
                v-model="searchItem2.recordTime"
                 @on-change="time3a"
                 format="yyyy-MM-dd HH:mm:ss"
                placeholder="记录时间"
                style="width: 100%"
              ></DatePicker>
            </FormItem>
          </Col> -->
          <Col span="6">
            <Button type="primary" class="marRight" @click="getDataList2">查询</Button>
          </Col>
        </Row>
      </Form>
    </div>
     <Table  border :columns="columns0" :data="tableData0"></Table>
     <Page show-total :total="total2" :page-size="pageSize2" @on-change="changePage2"  style="margin:20px auto;text-align:center"/>
    </Modal>
  </div>
</template>

<script>
import { getToken } from '@/libs/util'
import {
  getTableData,
  add,
  update,
  downExcel,
  del,findByMaintainRecordId,delByMaintainRecordId,findByMaintainPlanId,delByMaintainPlanId
} from '@/api/repairRecord'
import {
  getSelectOption,
  getAllPeople,getTime,getAllEqu
} from '@/api/select'
import {
  getTableData2
} from '@/api/repairPlan'
export default {
  data() {
    return {
      btnClick:false,
      loading:true,
      pageNo2: 1,
      pageSize2: 10,
      total2: 0,
      recordName: localStorage.getItem('recordUserName'),
      recordId:localStorage.getItem('recordUserId'),
      recordTime:getTime(),
      modal0:false,
      modal1: false,
      modal2: false,
      title1:'新增记录',
      delIndex: 0,
      pageNo: 1,
      pageSize: 10,
      total: 0,
       fileheader: {
        Authorization: 'Bearer ' + (getToken() ? getToken() : '')
      },
      peopleList:[],
      allEquList: [],
      allEquList2: [],
      powerStationList:[],
      JZnumberList:[],
      HBnumberList:[],
      maintainCategoryList:[],
      maintainStatusList:[],
      maintainContentList:[],
      searchItem: {
      },
      searchItem2: {
        aircrewNumber: "",
        repairCode: "",
        startTime: "",
        endTime: "",
        recordName:"",
        recordTime:""
      },
      formItem: {

      },
      yichangForm:{
        picUrl:''
      },
      fujianForm:{
        url:''
      },
      columns: [
        {
          type: "index",
          width: 60,
          title: "序号",
          align: "center"
        },
        {
          title: "电站",
          key: "powerStation"
        },
        {
          title: "HD编号",
          key: "hdNumber"
        },
        {
          title: "机组编号",
          key: "aircrewNumber"
        },
        {
          title: "维修编号",
          key: "maintainCode"
        },
        {
          title: "开始时间",
          key: "planStartTime"
        },
        {
          title: "完成时间",
          key: "planEndTime"
        },
        {
          title: "维修工期",
          key: "maintainDays"
        },
        {
          title: "维修类别",
          key: "maintainTypeDisplayName"
        },
        {
          title: "维修状态",
          key: "maintainStatusDisplayName"
        },
        {
          title: "记录人",
          key: "recordName"
        },
        {
          title: "记录时间",
          key: "recordTime",
          width:150
        },
        {
          title: "操作",
          key: "action",
          width: 150,
          align: "center",
          render: (h, params) => {
            return h("div", [
              h(
                "Button",
                {
                  props: {
                    type: "primary",
                    size: "small"
                  },
                  style: {
                    marginRight: "5px"
                  },
                  on: {
                    click: () => {
                      this.edit(JSON.stringify(params));
                    }
                  }
                },
                "编辑"
              ),
              h(
                "Button",
                {
                  props: {
                    type: "error",
                    size: "small"
                  },
                  on: {
                    click: () => {
                      this.openDel(params.row.id)
                    }
                  }
                },
                "删除"
              )
            ]);
          }
        }
      ],
      tableData: [],

      columns2: [
        {
          type: 'index',
          title: "序号",
          width: 60,
          align: 'center'
        },
        {
          title: "功能位置",
          key: "location"
        },
        {
          title: "异常描述",
          key: "description"
        },
        {
          title: "处理结果",
          key: "result"
        },
        {
          title: "图片",
          key: "picUrl",
          align:"center",
          render: (h, params) => {
            return h('img' ,{
                          domProps: {
                            align: 'center',
                            src: params.row.picUrl,
                          },
                          style: {
                            width:'50px',
                            height: '50px',
                            margin:'10px'
                          },
                          on: {
                            click: () => {

                              },
                            }
                          })
          }
        },
        {
          title: "记录人",
          key: "recordName",
        },
        {
          title: "操作",
          key: "action",
          align: "center",
          render: (h, params) => {
            return h("div", [
              h(
                "Button",
                {
                  props: {
                    type: "error",
                    size: "small"
                  },
                  on: {
                    click: () => {
                      this.remove2(params.index,params.row.id);
                    }
                  }
                },
                "删除"
              ),
              h(
                "Button",
                {
                  props: {
                    type: "primary",
                    size: "small"
                  },
                  style: {
                    marginLeft:'10px'
                  },
                  on: {
                    click: () => {
                      this.xiazai(params.row.picUrl);
                    }
                  }
                },
                "下载图片"
              )
            ]);
          }
        }
      ],
      tableData2: [],
      columns3: [
        {
          type: "index",
          width: 60,
          title: "序号",
          align: "center"
        },
        {
          title: "标题",
          key: "title"
        },
        {
          title: "上传人",
          key: "uploadUserName"
        },
        {
          title: "附件名称",
          key: "url",
          render: (h, params) => {
            return h("div",params.row.url.substring(params.row.url.lastIndexOf('/')+1));
          }
        },
        {
          title: "操作",
          key: "action",
          align: "center",
          render: (h, params) => {
            return h("div", [
              h(
                "Button",
                {
                  props: {
                    type: "error",
                    size: "small"
                  },
                  on: {
                    click: () => {
                      this.remove3(params.index,params.row.id);
                    }
                  }
                },
                "删除"
              ),
              h(
                "Button",
                {
                  props: {
                    type: "primary",
                    size: "small"
                  },
                  style: {
                    marginLeft:'10px'
                  },
                  on: {
                    click: () => {
                      this.xiazai(params.row.url);
                    }
                  }
                },
                "下载附件"
              )
            ]);
          }
        }
      ],
      tableData3:[],
      columns0: [
        {
          type: "index",
          width: 60,
          title: "序号",
          align: "center"
        },
        {
          title: "电站",
          key: "powerStation"
        },
        {
          title: "HD编号",
          key: "hdNumber"
        },
        {
          title: "机组编号",
          key: "aircrewNumber"
        },
        {
          title: "维修编号",
          key: "maintainCode"
        },
        {
          title: "计划开始时间",
          key: "planStartTime"
        },
        {
          title: "计划完成时间",
          key: "planEndTime"
        },
        {
          title: "记录人",
          key: "recordName"
        },
        {
          title: "记录时间",
          key: "recordTime"
        },
        {
          title: "选择",
          key: "action",
          align: "center",
          render: (h, params) => {
            return h("div", [
              h(
                "Button",
                {
                  props: {
                    type: "error",
                    size: "small"
                  },
                  on: {
                    click: () => {
                      this.checkdata(params.row);
                    }
                  }
                },
                "选择"
              )
            ]);
          }
        }
      ],
      tableData0: [],
    };
  },
  methods: {
    downBtn(){
      downExcel(this.searchItem).then(res => {
         const blob = new Blob([res], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;'});

        const ie = navigator.userAgent.match(/MSIE\s([\d.]+)/),
            ie11 = navigator.userAgent.match(/Trident\/7.0/) && navigator.userAgent.match(/rv:11/),
            ieEDGE = navigator.userAgent.match(/Edge/g),
            ieVer = (ie ? ie[1] : (ie11 ? 11 : (ieEDGE ? 12 : -1)));
        console.log('ie:' + ie);
        console.log('ieVer:' + ieVer);
        if (ie && ieVer < 10) {
            this.message.error('No blobs on IE<10');
            return;
        }
        if (ieVer > -1) {
            window.navigator.msSaveBlob(blob, '维修记录.xlsx');
        } else {
            const url = window.URL.createObjectURL(blob);
            let link = document.createElement('a');
            link.setAttribute('href', url);
            link.setAttribute('download', '维修记录.xlsx');
            document.body.appendChild(link);
            link.click();
            document.body.removeChild(link);
        }

        // const blob = new Blob([res]);//处理文档流
        //   const fileName = '维修记录.xlsx';
        //   const elink = document.createElement('a');
        //   elink.download = fileName;
        //   elink.style.display = 'none';
        //   elink.href = URL.createObjectURL(blob);
        //   document.body.appendChild(elink);
        //   elink.click();
        //   URL.revokeObjectURL(elink.href); // 释放URL 对象
        //   document.body.removeChild(elink);
      })
    },
    xiazai(url){
       window.open(url)
    },
    fileSuccess (response, file, fileList) {
      this.yichangForm.picUrl = response.data
    },
    fileSuccess2 (response, file, fileList) {
      this.fujianForm.url = response.data
    },
    addYc(){
      if(this.yichangForm.location==''||this.yichangForm.location==undefined){
        this.$Message.info('请填写功能位置！');
        return false;
      }
      if(this.yichangForm.description==''||this.yichangForm.description==undefined){
        this.$Message.info('请填写异常描述！');
        return false;
      }
      if(this.yichangForm.result==''||this.yichangForm.result==undefined){
        this.$Message.info('请填写处理结果！');
        return false;
      }
      this.yichangForm.recordName=this.recordName;
      this.yichangForm.recordId=this.recordId;
      this.tableData2.push(this.yichangForm);
      this.yichangForm={picUrl:''};
    },
    addFj(){
      if(this.fujianForm.title==''||this.fujianForm.title==undefined){
        this.$Message.info('请填写附件标题！');
        return false;
      }
      if(this.fujianForm.url==''||this.fujianForm.url==undefined){
        this.$Message.info('请选择附件！');
        return false;
      }
      this.fujianForm.uploadUserName=this.recordName;
      this.fujianForm.uploadUserId=this.recordId;
      this.tableData3.push(this.fujianForm);
      this.fujianForm={url:''};
    },
    getSelect1(e){
       var arry=this.maintainCategoryList.filter(item => item.id==e)
       this.formItem.maintainTypeDisplayName=arry[0].displayName
       this.formItem.maintainTypeValue=arry[0].value
    },
    getSelect2(e){
       var arry=this.maintainStatusList.filter(item => item.id==e)
       this.formItem.maintainStatusDisplayName=arry[0].displayName
       this.formItem.maintainStatusValue=arry[0].value
    },
    getSelect3(e){
       var arry=this.maintainContentList.filter(item => item.id==e)
       this.formItem.maintainContentDisplayName=arry[0].displayName
       this.formItem.maintainContentValue=arry[0].value
    },
    //获取所有人员
    getAllPeople(){
      getAllPeople(
        null
      ).then(res => {
        this.peopleList = res.data
      }).catch(err => {
        console.error('err>' + JSON.stringify(err))
      })
    },
    // 获取电站类型列表
    // powerStation () {
    //   getSelectOption(
    //     {
    //       code: 'dianzhan'
    //     }
    //   ).then(res => {
    //     this.powerStationList = res.data
    //   }).catch(err => {
    //     console.error('err>' + JSON.stringify(err))
    //   })
    // },
    maintainCategory () {
      getSelectOption(
        {
          code: 'maintainCategory'
        }
      ).then(res => {
        this.maintainCategoryList = res.data
      }).catch(err => {
        console.error('err>' + JSON.stringify(err))
      })
    },
    maintainStatus () {
      getSelectOption(
        {
          code: 'maintainStatus'
        }
      ).then(res => {
        this.maintainStatusList = res.data
      }).catch(err => {
        console.error('err>' + JSON.stringify(err))
      })
    },
    maintainContent () {
      getSelectOption(
        {
          code: 'maintainContent'
        }
      ).then(res => {
        this.maintainContentList = res.data
      }).catch(err => {
        console.error('err>' + JSON.stringify(err))
      })
    },
    // JZnumber () {
    //   getSelectOption(
    //     {
    //       code: 'jizu_code'
    //     }
    //   ).then(res => {
    //     this.JZnumberList = res.data
    //   }).catch(err => {
    //     console.error('err>' + JSON.stringify(err))
    //   })
    // },
    time1(e){
      this.searchItem.startTime = e
    },
    time2(e){
      this.searchItem.endTime = e
    },
    time3(e){
      this.searchItem.recordStartTime = e[0]
      this.searchItem.recordEndTime = e[1]
    },
    time4(e){
      this.formItem.planStartTime = e
    },
    time5(e){
      this.formItem.planEndTime = e
      this.getmaintainDays()
    },
    time1a(e){
      this.searchItem2.startTime = e
    },
    time2a(e){
      this.searchItem2.endTime = e
    },
    time3a(e){
      this.searchItem2.recordTime = e
    },
    changePage2 (pageNo) {
      this.pageNo2 = pageNo
      this.getDataList2()
    },
    getmaintainDays(){
      let start=new Date(this.formItem.planStartTime).getTime()
      let end=new Date(this.formItem.planEndTime).getTime();
      let day=end-start;
      this.formItem.maintainDays=parseInt(day/(1000*60*60*24));
    },
    openDel (index) {
      this.modal2 = true
      this.delIndex = index
    },
    remove(id) {
      del({ id: id }).then(res => {
        if (res.code == 0) {
          this.$Message.info('删除成功')
          this.pageNo=1
          this.getDataList()
        } else {
          this.$Message.info(res.message)
        }
      }).catch(err => {
        console.error('err>' + JSON.stringify(err))
      })
    },
    remove2(index,id) {
      this.tableData2.splice(index, 1);
      delByMaintainPlanId({ id: id }).then(res => {
        if (res.code == 0) {
          this.$Message.info('删除成功')
        } else {
          this.$Message.info(res.message)
        }
      })
    },
    remove3(index,id) {
      this.tableData3.splice(index, 1);
      delByMaintainRecordId({ id: id }).then(res => {
        if (res.code == 0) {
          this.$Message.info('删除成功')
        } else {
          this.$Message.info(res.message)
        }
      })
    },
    add () {
      this.title1 = '新增记录'
      this.modal0 = true
    },
    edit (params) {
      this.title1 = '编辑记录'
      console.log(params)
      this.formItem = JSON.parse(params).row
      this.modal1 = true
      findByMaintainPlanId({maintainPlanId:JSON.parse(params).row.id}).then(res => {
        if (res.code == 0) {
          this.tableData2 = res.data
        }
      })
      findByMaintainRecordId({maintainRecordId:JSON.parse(params).row.id}).then(res => {
        if (res.code == 0) {
          this.tableData3 = res.data
        }
      })
      this.allEquList2 = this.allEquList.filter(item => item.powerStation == this.formItem.powerStation);
      let arr2 = this.allEquList2.map(function(item) {
        return item.hdNumber;
      });
      this.HBnumberList = [...new Set(arr2)];

      let arr3 = this.allEquList2.filter(item => item.hdNumber == this.formItem.hdNumber);
      let arr4 = arr3.map(function(item) {
        return item.aircrewNumber;
      });
      this.JZnumberList = [...new Set(arr4)];
    },
    ok() {
      this.btnClick=true;
      let params=this.formItem;
      params.recordName=this.recordName;
      params.recordId=this.recordId;
      params.recordTime=this.recordTime;
      for(var i=0;i<this.tableData2.length;i++){
        params["anomalyAddDtoList["+i+"].location"]=this.tableData2[i].location;
        params["anomalyAddDtoList["+i+"].description"]=this.tableData2[i].description;
        params["anomalyAddDtoList["+i+"].picUrl"]=this.tableData2[i].picUrl;
        params["anomalyAddDtoList["+i+"].result"]=this.tableData2[i].result;
        params["anomalyAddDtoList["+i+"].recordId"]=this.tableData2[i].recordId;
        params["anomalyAddDtoList["+i+"].recordName"]=this.tableData2[i].recordName;
      }
      for(var i=0;i<this.tableData3.length;i++){
        params["attachAddDtoList["+i+"].title"]=this.tableData3[i].title;
        params["attachAddDtoList["+i+"].uploadUserId"]=this.tableData3[i].uploadUserId;
        params["attachAddDtoList["+i+"].uploadUserName"]=this.tableData3[i].uploadUserName;
        params["attachAddDtoList["+i+"].url"]=this.tableData3[i].url;
      }
      if(params.id){
          delete params._index;
          delete params._rowKey;
          params.planStartTime=this.timeFormat(params.planStartTime);
          params.planEndTime=this.timeFormat(params.planEndTime);
          update(params).then(res => {
            if (res.code == 0) {
              this.$Message.info('编辑成功')
              this.getDataList()
              this.modal1=false;
              this.btnClick=false;
            } else {
              this.$Message.info(res.message)
              this.btnClick=false;
            }
          }).catch(err => {
            console.error('err>' + JSON.stringify(err))
          })
      }else{

          add(params).then(res => {
            if (res.code == 0) {
              this.$Message.info('新增成功')
              this.getDataList()
              this.modal1=false;
              this.btnClick=false;
            } else {
              this.$Message.info(res.message)
              this.btnClick=false;
            }
          }).catch(err => {
            console.error('err>' + JSON.stringify(err))
          })
      }

    },
    timeFormat (time) {
      if(time instanceof Date==false){
        return time
      }
                const dateTime = new Date(time)
                const year = dateTime.getFullYear()
                const month = this.addZero(dateTime.getMonth() + 1)
                const date = this.addZero(dateTime.getDate())
                const hour = this.addZero(dateTime.getHours())
                const minute = this.addZero(dateTime.getMinutes())
                const second = this.addZero(dateTime.getSeconds())
                return year+"-"+month+"-"+date+" "+hour+":"+minute+":"+second
            },
            addZero (v) {
                return v < 10 ? '0' + v : v
            },
    /** 分页 */
    changePage (pageNo) {
      this.pageNo = pageNo
      this.getDataList()
    },
    getDataList () {
      let params = {
        pageNo: this.pageNo,
        pageSize: this.pageSize,
        aircrewNumber:this.searchItem.aircrewNumber,
        powerStation:this.searchItem.powerStation,
        hdNumber:this.searchItem.hdNumber,
        maintainCode:this.searchItem.maintainCode,
        planEndTime:this.searchItem.endTime,
        planStartTime:this.searchItem.startTime,
        recordName:this.searchItem.recordName,
        recordStartTime:this.searchItem.recordStartTime,
        recordEndTime:this.searchItem.recordEndTime
      }

      getTableData(params).then(res => {
        if (res.code == 0) {
          this.total = res.data.total
          this.tableData = res.data.list
          this.loading=false
        }
      }).catch(err => {
        console.error('err>' + JSON.stringify(err))
      })
    },
     getDataList2 () {
      let params = {
        pageNo: this.pageNo2,
        pageSize: this.pageSize2,
        aircrewNumber:this.searchItem2.aircrewNumber,
        powerStation:this.searchItem2.powerStation,
        hdNumber:this.searchItem2.hdNumber,
        maintainCode:this.searchItem2.repairCode,
        planEndTime:this.searchItem2.endTime,
        planStartTime:this.searchItem2.startTime,
        recordName:this.searchItem2.recordName,
        recordTime:this.searchItem2.recordTime
      }

      getTableData2(params).then(res => {
        if (res.code == 0) {
          this.total2 = res.data.total
          this.tableData0 = res.data.list
        }
      }).catch(err => {
        console.error('err>' + JSON.stringify(err))
      })
    },
    getAllEqument() {
      getAllEqu(null).then(res => {
        this.allEquList = res.data;
        let arr = res.data.map(function(item) {
          return item.powerStation;
        });
        this.powerStationList = [...new Set(arr)];
      });
    },
    getHd(e) {
      this.JZnumberList = [];
      this.allEquList2 = this.allEquList.filter(item => item.powerStation == e);
      let arr2 = this.allEquList2.map(function(item) {
        return item.hdNumber;
      });
      this.HBnumberList = [...new Set(arr2)];
    },
    getJz(e) {
      let arr = this.allEquList2.filter(item => item.hdNumber == e);
      let arr2 = arr.map(function(item) {
        return item.aircrewNumber;
      });
      this.JZnumberList = [...new Set(arr2)];
    },
    getMode(e){
      let arr = this.allEquList2.filter(item => item.hdNumber == this.formItem.hdNumber&&item.aircrewNumber == e)
      this.formItem.model=arr[0].model
    },
    getHd2(e) {
      this.JZnumberList = [];
      this.allEquList2 = this.allEquList.filter(item => item.powerStation == e);
      let arr2 = this.allEquList2.map(function(item) {
        return item.hdNumber;
      });
      this.HBnumberList = [...new Set(arr2)];
    },
    getJz2(e) {
      let arr = this.allEquList2.filter(item => item.hdNumber == e);
      let arr2 = arr.map(function(item) {
        return item.aircrewNumber;
      });
      this.JZnumberList = [...new Set(arr2)];
    },
    checkdata(data){
      console.log(data)
      this.modal0=false;
      this.modal1=true;
      this.formItem=data;
      this.formItem.maintainPlanId=data.id;
      this.formItem.maintainTypeDictId=data.maintainTypeDictId;
      delete this.formItem.id;
    }
  },
  created() {
     this.getAllEqument();
    this.maintainCategory();
    this.maintainStatus();
    this.maintainContent();
     this.getAllPeople();
    this.getDataList();
    this.getDataList2();
  }
};
</script>

<style lang="less">
.repairRecord {
  background: #fff;
  height: 100%;
  padding: 15px;
  font-size: 14px;
  .searchDiv {
    .marRight {
      margin-right: 15px;
    }
  }
  .ivu-form-item {
    margin-bottom: 15px;
  }
}
.baseTitle {
    font-weight: bold;
    font-size:16px;
    margin-bottom:10px;
  }
 .xzjz  {
   .ivu-form-item {
    margin-bottom: 10px;
  }
 }
</style>
